﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using KVB.Common;

namespace Customer_Profile.CRM.DBDao
{
    public class SmsDao
    {
        public static DataSet getSMSList(string strWhere)          //搜索Deals
        {
            string strSQL = "SELECT sms_id,sms_title,sms_content,input_userid,input_username,input_datetime,(SELECT CodeName FROM dbo.TP_TCode WHERE CodeValue=s.sms_status AND TypeID=(SELECT ID FROM dbo.TP_TType WHERE CodeTypeName='SMSStatus')) sms_status  FROM dbo.sms_content s where 1=1 ";
            strSQL += strWhere;
            strSQL += " ORDER BY sms_id DESC";
            //Log.WriteDefaultLog("SQL:", strSQL);
            DataSet ds = null;
            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                ds = DB.ExecuteDataset(conn, CommandType.Text, strSQL);
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("SmsDao.getSMSList", e.Message + "SQL:" + strSQL);
                throw e;
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
            return ds;
        }

        public static DataSet getSMSPhoneList(string seq_no)          //搜索Deals
        {
            string strSQL = "SELECT seq_no,sms_phoneno,send_date,remark,(SELECT CodeName FROM dbo.TP_TCode WHERE CodeValue=s.status AND TypeID=(SELECT ID FROM dbo.TP_TType WHERE CodeTypeName='SMSStatus')) status  FROM dbo.sms_phoneno s where sms_id =" + seq_no;
            
            DataSet ds = null;
            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                ds = DB.ExecuteDataset(conn, CommandType.Text, strSQL);
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("SmsDao.getSMSPhoneList", e.Message + "SQL:" + strSQL);
                throw e;
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
            return ds;
        }
    }
}